﻿using blackhouse.BlackApart.Business;
using blackhouse.BlackApart.Business.Apartments;
using blackhouse.BlackApart.Business.Reservations;
using blackhouse.BlackApart.Web.Navigation;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace blackhouse.StareKino.QuartzActions.ASyncMails {
    public partial class _2 : ReservationMailTemplate {

        private Factory factory = Factory.Instance();
        private string clientPrefferCurrency;
        private DateTime paymentDate;

        protected DateTime PaymentDate {
            get {
                if (this.paymentDate == null) {
                    this.paymentDate = this.Reservation.ArrivalDate.AddDays(-4);
                    if (this.paymentDate.Date < DateTime.Now.Date)
                        this.paymentDate = DateTime.Now.Date;
                }
                return this.paymentDate;
            }
        }

        protected override void OnLoad(EventArgs e) {
            base.OnLoad(e);

            if (this.Reservation.Client != null)
                this.clientPrefferCurrency = this.Reservation.Client.PrefferCurrency;
            this.ltlReservationNumber.Text = this.Reservation.ReservationNumber;
            if (this.Reservation.PaymentType.Key.Equals("platnosc-przelewem")) {
                this.phAcountPayment.Visible = true;
            } else
                this.phAcountPayment.Visible = false;
            this.PopulateClient();
            this.PopulateReservationInfo();

            this.reservationDetailTable.Reservation = this.Reservation;
            this.reservationDetailTable.CurrencyCode = this.clientPrefferCurrency;

            this.AdditionalInformation.Reservation = this.Reservation;
        }

        private void PopulateReservationInfo() {
            this.ltlReservationPeriod.Text = this.Reservation.PrintStayPeriod();
            this.ltlReservationPeopleCount.Text = this.Reservation.PersonCount.ToString();
            this.ltlArrivalTime.Text = this.Reservation.PrintArrivalDateTime();
        }

        private void PopulateClient() {
            if (this.Reservation.Client == null) return;
            this.ltlClientName.Text = this.Reservation.Client.FirstName + " " + this.Reservation.Client.LastName;
            this.ltlClientEMail.Text = this.Reservation.Client.EMail;
            this.ltlClientPhone.Text = this.Reservation.Client.PhoneNumber;
        }

    }
}